import { HTTP as SERVICE } from "@/tools";

import { StandardPagingResult, StandardQuery } from "./standard";
export interface NoticeQueryParams extends Partial<StandardQuery> {
  type: string;
  title?: string;
  content?: string;
}
export interface NoticeInfoListItem {
  cancelTime: string;
  content: string;
  createTime: string;
  createUser: number;
  id: number;
  publicOrgId: number;
  publicOrgName: string;
  publicTime: string;
  publicUserId: number;
  publicUserName: string;
  status: number;
  title: string;
  type: number;
  updateTime: string;
  updateUser: number;
}
export async function getNoticeList(params: NoticeQueryParams) {
  return SERVICE.post<any, StandardPagingResult<NoticeInfoListItem>>(
    "/sysNotice/page",
    params
  );
}

export interface NoticeSaveParams {
  // 公告内容
  content: string;
  // 公告标题
  title: string;
  // 公告类型
  type: 1 | 2;
  // 发布状态
  status: number;
  // 需要通知的员工id列表
  noticeUserIdList: number[];
  // 公告的唯一编号
  id: number;
  publicTime: string;
}
export interface NoticeSaveParamsModel extends NoticeSaveParams {
  noticeM: number[],
  noticeA: number[]
}
export async function SaveNoticeInfo(params: NoticeSaveParams) {
  const { id, ...otherinfo } = params;
  return SERVICE.post(
    `/sysNotice/${id ? "edit" : "add"}`,
    id ? params : otherinfo
  );
}
export interface NoticeDetail {
  // 撤回时间
  cancelTime: string;
  // 内容
  content: string;
  // id
  id: number;
  // 通知到的用户id集合
  noticeUserIdList: [];
  // 通知到的用户阅读信息集合
  noticeUserReadInfoList: [];
  // 发布通知的机构id
  publicOrgId: number;
  // 发布机构名称
  publicOrgName: string;
  // 发布时间
  publicTime: string;
  // 发布人id
  publicUserId: number;
  // 发布人姓名
  publicUserName: string;
  // 状态见 statusMap
  status: number;
  // 标题
  title: string;
  // 通知类型(见options)
  type: 1 | 2;
}

export async function getNoticeDetail(params: Partial<NoticeSaveParams>) {
  return SERVICE.post<any, NoticeDetail>("/sysNotice/detail", params);
}

export async function NoticeDelete(id: number) {
  return SERVICE.post("/sysNotice/delete", { id, status: 2 });
}

export interface NoticeQueryPrams extends Partial<StandardQuery> {
  type?: 1 | 2;
  readStatus?: 0 | 1
}

export interface NoticeQueryResultItem {
  cancelTime: string;
  content: string;
  id: number;
  publicOrgId: number;
  publicOrgName: string;
  publicTime: string;
  publicUserId: number;
  publicUserName: string;
  readStatus: number;
  readTime: string;
  status: number;
  title: string;
  type: number;
}
/**
 *
 * @param type 1表示通知,2表示公告
 * @returns
 */
export async function getCurrentUserNotice(params: NoticeQueryPrams) {
  return SERVICE.post<any, StandardPagingResult<NoticeQueryResultItem>>(
    "/sysNotice/received",
    params
  );
}
